package com.cltech.repository.sys;

import com.cltech.dto.TreeNode;
import com.cltech.entity.sys.SysPermission;
import com.cltech.frame.base.BaseRepository;
import com.cltech.frame.query.SmartQuery;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Set;

/**
 * Created by Administrator on 2019/4/14.
 */
public interface SysPermissionRepository extends BaseRepository<SysPermission, String> {
    Set<SysPermission> findByIdIsIn(List<String> ids);
    SysPermission findByPermissionCode(String permissionCode);
    @SmartQuery(value = "select a.id `key`, a.parent_id pid, "
            + "a. name title, a.permission_code code, a.type type, "
            + "a.link link, a.icon icon, case when c.id is null then '0' else '1' end selected "
            + "from sys_permission a left join sys_permission_role b on a.id = b.permission_id "
            + "left join sys_role c on b.role_id = c.id "
            +"<#if roleId??>"
            + "and c.id = :roleId "
            +"</#if>"
            + "where 1=1 "
            +"<#if sysPermissionType??>"
            +"a.type = :sysPermissionType "
            +"</#if>"
            +"<#if sysPermissionlevel??>"
            +"a.level = :sysPermissionlevel "
            +"</#if>",freemarkerTemplate=true)
    List<TreeNode>findAllPermissionsTreeByRole(@Param("roleId")String roleId,
                                               @Param("sysPermissionType")String sysPermissionType,
                                               @Param("sysPermissionlevel")Integer sysPermissionlevel);
}
